﻿namespace Homework_Snake1015
{
    class Information
    {
        string[] infoList;
        ConsoleColor[] col;
        int index;//指针
        int maxCount;//最大存储量
        int offsetX, offsetY;
        bool isPrint = true;
        public Information(int x, int y)
        {
            index = 0;
            maxCount = 10;
            infoList = new string[maxCount];
            col = new ConsoleColor[maxCount];
            offsetX = x;
            offsetY = y;
        }

        public void AddInfo(string info,ConsoleColor infocol)
        {
            if (index > maxCount - 1)
            {
                index = maxCount - 1;
                FowardInfoArray();
            }
            col[index] = infocol;
            infoList[index++] = info;
        }

        void FowardInfoArray()
        {
            for (int i = 0; i < maxCount - 1; i++)
            {
                infoList[i] = infoList[i + 1];
                col[i] = col[i + 1];
            }
        }

        void PrintFrame()
        {
            for (int k = 0; k < offsetX+1; k++)
            {
                for (int i = 0; i < 12; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        string temp = "";
                        if (i == 0 && j == 0)
                        {
                            /*MyPrint("┌", offsetX + j, offsetY + i);*/
                            temp = "┌";
                        }
                        else if (i == 0 && j == 9)
                        {
                            /*MyPrint("┐", offsetX + j, offsetY + i);*/
                            temp = "┐";
                        }
                        else if (i == 11 && j == 0)
                        {
                            /*MyPrint("└", offsetX + j, offsetY + i);*/
                            temp = "└";
                        }
                        else if (i == 11 && j == 9)
                        {
                            /*MyPrint("┘", offsetX + j, offsetY + i);*/
                            temp = "┘";
                        }
                        else if (i == 0 || i == 11)
                        {
                            /* MyPrint("一", offsetX + j, offsetY + i);*/
                            temp = "─";
                        }
                        else if (j == 0 || j == 9)
                        {
                            /* MyPrint("|", offsetX + j, offsetY + i);*/
                            temp = "│";
                        }
                        else
                        {
                            temp = "  ";
                        }
                        MyPrint(temp, k + j, offsetY + i);
                        if (j == 0 && k > 0)
                        {
                            MyPrint(" ", k -1 + j, offsetY + i);
                        }
                    }
                    
                }
                Thread.Sleep(100);
            }
            MyPrint("日志", offsetX+4 , offsetY-1);

        }

        void PrinText(ConsoleColor color)
        {
            for (int i = 0; i < index; i++)
            {
                //if (i == index -1)
                MyPrint(infoList[i], offsetX + 1, offsetY + 1 + i, col[i]);
            }
        }

        public void PrintInfo(ConsoleColor color)
        {
            
            if (isPrint)
            {
                PrintFrame();
            }
            isPrint = false;
            PrinText(color);
        }

        void MyPrint(string str, int x, int y, ConsoleColor color = ConsoleColor.White)
        {
            Console.SetCursorPosition(x * 2, y);
            Console.ForegroundColor = color;
            Console.Write(str);
            Console.ResetColor();
        }
    }
}
